<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of shuffle</title>
  <meta name="keywords" content="shuffle">
  <meta name="description" content="Shuffles the order of a vector or 2D matrix">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html . -->
<h1>shuffle
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Shuffles the order of a vector or 2D matrix</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [shuffled idx] = shuffle(mat,dim) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Shuffles the order of a vector or 2D matrix

 [shuffled] = shuffle(mat,[dim])

 DIM (optional, default = 1), determines which dimension to use to
 shuffle the matrix

 Can't deal with &gt;2D matrices. Any suggestions?</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="scramble_regressors.html" class="code" title="function [subj] = scramble_regressors(subj,regsname,selname,new_regsname,varargin)">scramble_regressors</a>	Scrambles your regressors for sanity-checking</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [shuffled idx] = shuffle(mat,dim)</a>
0002 
0003 <span class="comment">% Shuffles the order of a vector or 2D matrix</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% [shuffled] = shuffle(mat,[dim])</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% DIM (optional, default = 1), determines which dimension to use to</span>
0008 <span class="comment">% shuffle the matrix</span>
0009 <span class="comment">%</span>
0010 <span class="comment">% Can't deal with &gt;2D matrices. Any suggestions?</span>
0011 
0012 <span class="comment">% This is part of the Princeton MVPA toolbox, released under the</span>
0013 <span class="comment">% GPL. See http://www.csbmb.princeton.edu/mvpa for more</span>
0014 <span class="comment">% information.</span>
0015 
0016 
0017 <span class="keyword">if</span> ~exist(<span class="string">'dim'</span>)
0018   dim = 1;
0019 <span class="keyword">end</span>
0020 
0021 <span class="keyword">if</span> isempty(mat)
0022   shuffled = [];
0023   <span class="keyword">return</span>
0024 <span class="keyword">end</span>
0025 
0026 <span class="keyword">if</span> ndims(mat)&gt;2
0027   error(<span class="string">'Can''t deal with multi-dimensional matrices'</span>);
0028 <span class="keyword">end</span>
0029 <span class="keyword">if</span> dim&lt;1
0030   error(<span class="string">'Dim must be greater than 1'</span>);
0031 <span class="keyword">end</span>
0032 <span class="keyword">if</span> dim&gt;ndims(mat)
0033   error(<span class="string">'Dims must be less than the number of dimensions in the matrix'</span>);
0034 <span class="keyword">end</span>
0035 
0036 <span class="keyword">if</span> isvector(mat)
0037   matsize = length(mat);
0038 <span class="keyword">else</span>
0039   matsize = size(mat,dim);
0040 <span class="keyword">end</span>
0041 
0042 [vals idx] = sort(rand([1 matsize]));
0043 
0044 <span class="keyword">if</span> isvector(mat)
0045   shuffled = mat(idx);
0046   <span class="keyword">return</span>
0047 <span class="keyword">end</span>
0048 
0049 <span class="keyword">switch</span>(dim)
0050  <span class="keyword">case</span> 1
0051   shuffled = mat(idx,:);
0052  <span class="keyword">case</span> 2
0053   shuffled = mat(:,idx);
0054  <span class="keyword">otherwise</span>
0055   error(<span class="string">'Can''t deal with matrices of &gt;3 dimensions'</span>);
0056 <span class="keyword">end</span>
0057</pre></div>
<hr><address>Generated on Tue 06-Sep-2005 22:11:31 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>